from flask import Blueprint, redirect, url_for

# 创建蓝图
from flask import request
from flask import session

admin_bp = Blueprint("admin", __name__)

# 切记一定要将views文件导入
from . import views


@admin_bp.before_request
def before_request():
    """请求之前对用户权限判断"""
    if not request.url.endswith(url_for("admin.admin_login")):
        # 获取is_admin 如果不是管理员，引导到新闻首页
        is_admin = session.get("is_admin", False)
        # 不是管理员
        if not is_admin:
            return redirect("/")
